﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Core;
using Core.LockStep;
using TMPro;

public interface IBattleAssetHelper : IHelperTag
{
    void CreatePlayer(int playerId);
    void Clear();
}

public class BattleAssetHelper : GameHelper, IBattleAssetHelper
{
    public override void OnInit()
    {
        BattleAssetTool.helper = this;
    }

    public override void OnDestroy()
    {
        BattleAssetTool.helper = null;
    }

    public async void CreatePlayer(int playerId)
    {
        var playerData = LockStepTool.CreateBackupData<BackupData1PlayerData>(playerId);
        playerData.playerId = playerId;

        var prefab = await LoadAssetAsync<GameObject>("Battle/Player/Player.prefab");
        GameObject player = GameObject.Instantiate(prefab);
        player.name = playerId.ToString();
        var nameTxt = player.GetComponentInChildren<TextMeshPro>();
        if (nameTxt != null)
            nameTxt.text = playerId.ToString();

        playerData.model.Data = player.transform;
    }

    public void Clear()
    {

    }
}